package com.ah.shanxi_demo.task;

import com.ah.shanxi_demo.common.enums.SyncEnum;
import com.ah.shanxi_demo.service.IOrderService;
import com.ah.shanxi_demo.service.IPolicyService;
import com.ah.shanxi_demo.service.ISyncService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 定时任务同步信息
 * @author zt 2020/8/21
 */
@Component
@EnableScheduling
public class SyncTaskExecutor{
    private static final Logger logger = LoggerFactory.getLogger(SyncTaskExecutor.class);


    @Autowired
    private ISyncService syncService;


    @Autowired
    private IPolicyService policyService;

    @Autowired
    private IOrderService orderService;


    @Scheduled(cron = "0 0/10 * * * ?")
    public void executorSimulationSync(){
        logger.info("executorSimulationSync 【start】");

        //模拟工单、策略数据更新
        orderService.syncSimulationOrder();
        policyService.syncSimulationPolicy();

        logger.info("executorSimulationSync 【end】");
    }

    /**
     * 每分钟同步部级平台信息
     * 有变化 便获取新的策略列表与工单列表
     */
//    @Scheduled(cron = "0 0/1 * * * ?")
    public void executorSync(){

        logger.info("executorSync start");

        //同步部级平台信息得到 同步指令
        SyncEnum syncEnum = syncService.stateSync();

        switch (syncEnum) {
            case ORDER:
                //工单数据更新
                orderService.syncOrder();
                break;
            case POLICY:
                //策略数据更新
                policyService.syncPolicy();
                break;
            case POLICY_ORDER:
                //工单、策略数据更新
                orderService.syncOrder();
                policyService.syncPolicy();
                break;
            case SYNC:
                break;
            default:
                logger.warn("executorSync: fail");
                break;
        }

        logger.info("executorSync end");
    }




}
